<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="org.hibernate.Session"%>
<%@ page import="org.hibernate.Transaction"%>
<%@ page import="com.zky.common.HibernateSessionFactory"%>
<%@ page import="org.hibernate.Query"%>
<%@ page import="com.zky.entity.Users1"%>
<%@ page import="java.io.PrintWriter"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'Users1DaoImp.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  <%
  	    response.setContentType("text/html");
		response.setCharacterEncoding("utf-8");
		PrintWriter ou = response.getWriter();
       List<Users1> list=new ArrayList<Users1>();
       String msg="";
       request.setCharacterEncoding("utf-8");
      String name1=request.getParameter("username");
        Session s = HibernateSessionFactory.getSession();
		 Transaction transaction = s.beginTransaction();
		  try{		
		   String hql="from Users1 as muser where muser.username=?";
			  Query query=s.createQuery(hql);
			  query.setString(0, name1);
			   list=query.list();
				if (null == list || list.size() == 0) {
				
				 ou.print(msg);
			    	//System.out.print(msg);
			    }
				else{
				    msg="用户名已存在";
					//System.out.print(msg);
					ou.print(msg);
					
				}
			   transaction.commit();
			   
			   }catch(Exception e){
			    e.printStackTrace();
			   }finally{
			     s.close();
		
	}
		
	               ou.flush();
		           ou.close();
		
		  %>
  </body>
</html>
